home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- '''Generic Internet address helper functions.'''
- import socket
- import dns.ipv4 as dns
- import dns.ipv6 as dns
- AF_INET = socket.AF_INET
-
- try:
- AF_INET6 = socket.AF_INET6
- except AttributeError:
- AF_INET6 = 9999
-
-
- def inet_pton(family, text):
- '''Convert the textual form of a network address into its binary form.
-
- @param family: the address family
- @type family: int
- @param text: the textual address
- @type text: string
- @raises NotImplementedError: the address family specified is not
- implemented.
- @rtype: string
- '''
- if family == AF_INET:
- return dns.ipv4.inet_aton(text)
- elif family == AF_INET6:
- return dns.ipv6.inet_aton(text)
- else:
- raise NotImplementedError
-
-
- def inet_ntop(family, address):
- '''Convert the binary form of a network address into its textual form.
-
- @param family: the address family
- @type family: int
- @param address: the binary address
- @type address: string
- @raises NotImplementedError: the address family specified is not
- implemented.
- @rtype: string
- '''
- if family == AF_INET:
- return dns.ipv4.inet_ntoa(address)
- elif family == AF_INET6:
- return dns.ipv6.inet_ntoa(address)
- else:
- raise NotImplementedError
-
-
- def af_for_address(text):
- '''Determine the address family of a textual-form network address.
-
- @param text: the textual address
- @type text: string
- @raises ValueError: the address family cannot be determined from the input.
- @rtype int
- '''
-
- try:
- junk = dns.ipv4.inet_aton(text)
- return AF_INET
- except:
-
- try:
- junk = dns.ipv6.inet_aton(text)
- return AF_INET6
- raise ValueError
-
-
-
-